package com.yuyou.tas.admin.service.impl;

import com.yuyou.tas.admin.entity.CommMessPushJob;
import com.yuyou.tas.admin.mapper.CommMessPushJobMapper;
import com.yuyou.tas.admin.service.ICommMessPushJobService;
import com.yuyou.tas.util.bean.ResBoolSimpleInfo;
import com.yuyou.tas.util.tool.Sequence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CommMessPushJobServiceImpl implements ICommMessPushJobService {

    @Autowired
    private CommMessPushJobMapper messPushJobMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return messPushJobMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(CommMessPushJob record) {
        Date now = new Date();
        record.setCreateTime(now);
        record.setUpdateTime(now);
        record.setInitTime(now);
        record.setHasTime(0);
        record.setId(Sequence.getSequence().nextId());
        return messPushJobMapper.insert(record);
    }

    @Override
    public CommMessPushJob selectByPrimaryKey(Long id) {
        return messPushJobMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(CommMessPushJob record) {
        return messPushJobMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public ResBoolSimpleInfo<String> addJob(Long f_id, Integer type, Integer status , String tag) {
        CommMessPushJob job = new CommMessPushJob();
        job.setfId(f_id);
        job.setMaxTime(0);
        job.setType(type);
        job.setMaxTime(0);
        job.setNeedRetry(0);
        job.setStatus(status);
        job.setTag(tag);

        this.insert(job);
        return new ResBoolSimpleInfo<>(true , null);
    }

    @Override
    public ResBoolSimpleInfo<String> updateJobStatusByFId(Long f_id, Integer status , String remark) {
        messPushJobMapper.updateJobStatusByFId(status , f_id , remark);
        return new  ResBoolSimpleInfo(true , null);
    }
}